from django.db import models
from django.contrib.auth.models import AbstractUser

# Create your models here.
# 用户表
#    id   username     password      phone
# int pk   varchar(50) varchar(100)  varchar(11)

class User(AbstractUser):
    # 添加额外的类属性
    mobile = models.CharField("手机号",max_length=11)

    def __str__(self):
        return self.username

    class Meta:
        db_table = 'user_tb'
        verbose_name = "用户表"
        verbose_name_plural = verbose_name


# 收获地址 表
#        id             receiver            receive_mobile      receive_addr       is_default   user_id
# 主键,django自动添加    收件人，varcher(50)       varcher(11)     varchar(100)        boolean        int
class Addr(models.Model):
    receiver = models.CharField("收件人", max_length=50)
    receive_mobile = models.CharField("手机号", max_length=11)
    receive_addr = models.CharField("收获地址", max_length=100)
    is_default = models.BooleanField("是否默认", default=False)
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="所属用户")

    def __str__(self):
        return self.receiver + " " + self.receive_mobile

    class Mate:
        db_table = "addr_tb"
        verbose_name_plural = "收获地址"
